Repository navigation
Python: model PyMongo collection reads as database sources - #22812
Open
kazuki-netizen wants to merge 1 commit into
Open
kazuki-netizen wants to merge 1 commit into
kazuki-netizen wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PyMongo collection reads are not currently modeled as sources under the opt-in
databasethreat model. As a result,py/sql-injectionmisses stored document values that are subsequently concatenated into SQL, including the list accumulation andstr.joinexample in #21775.This adds a
ThreatModelSourcefor the existingMongoCollectionCallmodel, following thedatabasesource convention used by PEP 249 fetch methods. It covers the already-modeled PyMongo and Flask-PyMongo collection read APIs and collection access paths. Sources become active whendatabase,local, orallis enabled; the default remote threat model is unchanged.Related to #21775.
Validation
mainat4af6ba60e60683f482a583f9d444f1286abafd1f, the new SQL fixture produced zero alerts with thedatabasethreat model enabled. With this change, it produces exactly eight alerts at the intended unsafe SQL constructions.find_onemethod are covered as negative cases. Library tests cover collection access variants, legacyfind_and_modify, and Flask-PyMongo; a separate query verifies that database sources are inactive by default.git diff --checkpassed.The focused test command was:
codeql test run --search-path=. --threads=2 --ram=4096 \ python/ql/test/library-tests/frameworks/pymongo \ python/ql/test/query-tests/Security/CWE-089-SqlInjection-database-threat-model \ python/ql/test/query-tests/Security/CWE-089-SqlInjection \ python/ql/test/query-tests/Security/CWE-089-SqlInjection-local-threat-model \ python/ql/test/query-tests/Security/CWE-943-NoSqlInjection \ python/ql/test/library-tests/frameworks/psycopg \ python/ql/test/library-tests/threat-models/defaultAI assistance was used for implementation and test development. The validation described above was executed locally. The complete Python test suite was not run.